//
//  HNTeacgerEvaluateView.m
//  BestLearning
//
//  Created by 星道 on 17/6/3.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "HNTeacgerEvaluateView.h"
#import "HNTeacgerEvaluateSelectRowView.h"

#define SelectRowViewH 40
#define TitleW  80
@implementation HNTeacgerEvaluateView
{
    NSMutableArray *_ContentArr;
    NSString *_Title;
    NSMutableArray *_Selection_Arr;
}

- (instancetype)init_Title:(NSString *)Title ContentArr:(NSArray *)ContentArr Y:(CGFloat)Y W:(CGFloat)W
{
    self = [super init];
    if (self)
    {
        _Title = Title;

        _ContentArr = [NSMutableArray array];
        _Selection_Arr = [NSMutableArray array];
        for (NSDictionary *Dict in ContentArr)
        {
            [_Selection_Arr addObject:Dict[@"selection"]];
            [_ContentArr addObject:Dict[@"content"]];
        }
        
        CGFloat x = 0;
        CGFloat y = Y;
        CGFloat w = W;
        CGFloat h = SelectRowViewH * ContentArr.count;
        self.frame = CGRectMake(x, y, w, h);
        
        [self CreatUI];
    }
    return self;
}


- (void)CreatUI
{
    for (int i=0; i<_ContentArr.count; i++)
    {
        HNTeacgerEvaluateSelectRowView *View = [[[NSBundle mainBundle] loadNibNamed:[HNTeacgerEvaluateSelectRowView description] owner:nil options:nil] lastObject];

        
        CGFloat x = TitleW;
        CGFloat y = i * SelectRowViewH;
        CGFloat w = SCREEN_WIDTH - TitleW;
        CGFloat h = SelectRowViewH;
        
        View.frame = CGRectMake(x, y, w, h);
        View.Title.text = _ContentArr[i];
        View.section = _Selection_Arr[i];
        [self addSubview:View];
    }
    

    
    
    UILabel *Title_Label = [[UILabel alloc] init];
    Title_Label.text = _Title;
    Title_Label.textAlignment = NSTextAlignmentLeft;
    Title_Label.textColor = [UIColor grayColor];
    Title_Label.font = [UIFont systemFontOfSize:14.f];
    Title_Label.numberOfLines = 0;
    
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = TitleW;
    CGFloat h = self.frame.size.height;
    Title_Label.frame = CGRectMake(x, y, w, h);
    
    [self addSubview:Title_Label];
    
    UIView *LineView = [UIView new];
    LineView.backgroundColor = ColorRGB(240, 240, 240);
    LineView.frame = CGRectMake(0, self.frame.size.height-1, SCREEN_WIDTH, 1);
    [self addSubview:LineView];
}




+ (NSInteger)SourceCount:(NSArray *)Arr
{
    NSInteger Index = 0;
    for (NSDictionary *Dict in Arr)
    {
        if ([Dict[@"selection"] integerValue] == 1)
        {
            Index += 7;
        }
        else if ([Dict[@"selection"] integerValue] == 2)
        {
            Index += 5;
        }
        else if ([Dict[@"selection"] integerValue] == 3)
        {
            Index += 3;
        }
        else if ([Dict[@"selection"] integerValue] == 4)
        {
            Index += 1;
        }
        else
        {
        }
        
    }
    return Index;
}
@end
